package com.xc.h05.controller.weichen;

import com.github.pagehelper.PageInfo;
import com.xc.h05.entity.Specialty;
import com.xc.h05.service.weichen.SpecialtyService;
import com.xc.h05.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/specialty")
public class SpecialtyController {
    @Autowired
    private SpecialtyService specialtyService;

    @PostMapping("/add")
    public R add(@RequestBody Specialty specialty){
        int add = specialtyService.add(specialty);
        if (add>0){
            return R.ok(specialty);
        }else {
            return R.error();
        }
    }
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable("id") int id){
        int delete = specialtyService.delete(id);
        if (delete>0){
            return R.ok(delete);
        }else {
            return R.error();
        }
    }
    @PostMapping("/deletes")
    public R deletes(@RequestBody List<Integer> list){
        int deletes = specialtyService.deletes(list);
        if (deletes>0){
            return R.ok(deletes);
        }else {
            return R.error();
        }
    }
    @PutMapping("/update")
    public R update(@RequestBody Specialty specialty){
        int update = specialtyService.update(specialty);
        if (update>0){
            return R.ok(specialty);
        }else {
            return R.error();
        }
    }
    @GetMapping("/findByPage")
    public R findByPage(int pageNum,int pageSize, Specialty specialty){
        PageInfo<Specialty> pageInfo = specialtyService.findByPage(pageNum, pageSize, specialty);
        return R.ok(pageInfo);
    }
    @GetMapping("/findAll")
    public R findAll(){
        List<Specialty> list = specialtyService.findAll();
        return R.ok(list);
    }



}
